home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / ListPair.sml < prev    next >
Encoding:
Text File  |  1996-07-03  |  858 b   |  33 lines  |  [TEXT/R*ch]

  1. (* ListPair *)
  2.  
  3. fun zip (xs, ys) = 
  4.     let fun h (x::xr) (y::yr) res = h xr yr ((x, y) :: res)
  5.       | h _       _       res = List.rev res
  6.     in h xs ys [] end;
  7.  
  8. fun unzip xys =
  9.     let fun h ([],          xs, ys) = (List.rev xs, List.rev ys)
  10.       | h ((x, y)::xyr, xs, ys) = h (xyr, x::xs, y::ys)
  11.     in h (xys, [], []) end;
  12.  
  13. fun map f (xs, ys) = 
  14.     let fun h (x::xr) (y::yr) res = h xr yr (f(x, y) :: res)
  15.       | h _       _       res = List.rev res
  16.     in h xs ys [] end;
  17.  
  18. fun app f (xs, ys) = 
  19.     let fun h (x::xr) (y::yr) = (f (x, y); h xr yr)
  20.       | h _       _       = ()
  21.     in h xs ys end;
  22.  
  23. fun all p (xs, ys) = 
  24.     let fun h (x::xr) (y::yr) = p(x, y) andalso h xr yr
  25.       | h _       _       = true
  26.     in h xs ys end;
  27.  
  28. fun exists p (xs, ys) = 
  29.     let fun h (x::xr) (y::yr) = p(x, y) orelse h xr yr
  30.       | h _       _       = false
  31.     in h xs ys end;
  32.  
  33.